# -*- coding: utf-8 -*-
import json

def getProvinceList(request):
    request.cursor_standard.execute('''
        select * from dict_province order by province_code
    ''')
    rows = request.cursor_standard.fetchall()
    return json.dumps(rows, ensure_ascii=False)

def getCityList(request):
    request.cursor_standard.execute(request.formatSql('''
        select * from dict_city 
        where province_id = '${province_id}'
        order by city_code
    '''))
    rows = request.cursor_standard.fetchall()
    return json.dumps(rows, ensure_ascii=False)
    
def insertCity(request):
    request.cursor_standard.execute(request.formatSql('''
        insert into dict_city(
            city_code,city_name,province_id
        )values(
            '${city_code}','${city_name}',${province_id}
        )
    '''))
    return str(request.cursor_standard.rowcount)

def updateCity(request):
    request.cursor_standard.execute(request.formatSql('''
        update dict_city
        set city_code = '${city_code}',
        city_name = '${city_name}'
        where city_id = ${city_id}
    '''))
    return str(request.cursor_standard.rowcount)